import React from 'react';
import {Link} from "react-router-dom";
import GUtils from "@/utils";
import classNames from "classnames";

const Config = (Action) => {
    const Handlers = {
        enabled({id,enabled,account}) {
            enabled=!enabled;
            let op = enabled ? "启用" :"禁用";
            GUtils.confirm(op,`确认${op}账号 [${account}] 吗?`,()=>{
                Action.enabled(id, enabled);
            });
        }
    }
    const columns = [
        //return  <Link to={`detail/view?id=${vo.id}`} className="mr-8">{v}</Link>;
        {title:"姓名",dataIndex:"username",width:120},
        {title:"账号",dataIndex:"account",width:120},
        {title:"管理门店",dataIndex:"shopName",width:160, render(v, vo) {
                let {PAGE_SHOP, PAGE_DETAIL}=window.CONFIG;
                let {shopList=[]} = vo;
                return <div>
                    {shopList && shopList.map((o,i)=><div key={i}>
                        <Link  to={`${PAGE_SHOP}${PAGE_DETAIL}?id=${o.id}`} className={classNames(o.enabled||"danger")}>{o.name} {o.enabled || GUtils.renderEnabledValue(o.enabled)}</Link>
                    </div>)}
                </div>
            }},
        {title:"状态",dataIndex:"enabled",width:60, render:GUtils.renderEnabledValue},


        {title: '操作',dataIndex: 'id',width: 60,render(id,vo){
                let {enabled} = vo;
                return <div>
                    {vo.enabled} {GUtils.renderEnabledLink(vo, "商家账号", "account", Action)}
                    <Link to={`detail/edit?id=${id}`} className="ml-8">编辑</Link>
                </div>
            }},
    ];
    return {
        ...window.CONFIG.getPagerConfig(Action), columns
    };
};


export default Config;
